package cn.edu.just.firstjavaapp.l20;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class ButtonClickHandlerDemo {
    public static void main(String[] args) {
        JFrame frame = new JFrame();
        frame.setLayout(new FlowLayout());
        frame.setBounds(100,100,400,300);
        JTextField textField = new JTextField();
        textField.setColumns(20);
        JButton button = new JButton("提交");
        MyButtonListener listener = new MyButtonListener(textField);
        button.addActionListener(listener);
        frame.add(textField);
        frame.add(button);
        frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        frame.setVisible(true);
    }
}

class MyButtonListener implements ActionListener{

    JTextField textField;
    public MyButtonListener(JTextField textField){
        this.textField = textField;
    }
    @Override
    public void actionPerformed(ActionEvent e) {
        System.out.println("我被点了"+textField.getText());
    }
}
